<?php
/*
 * @Description: 
 * @Author: Leequik
 * @Date: 2025-03-21 22:21:10
 * @LastEditTime: 2025-03-26 10:42:28
 * @LastEditors: Leequik
 */

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Jobs\QueueJobs;

class QueuePriority extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:queue-priority';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '优先级队列';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        //
        $this->priority_queue();
    }

    //优先级队列
     /** 指定队列消费优先级
      *
      * 发送队列命令：php artisan app:queue-priority
      * 消费信息命令：php artisan queue:work --queue=B,A,default
      */
      public function priority_queue(){
        for ($i = 6; $i > 0; $i--) {
            $queue = 'default';
            if ($i%3 == 1) {
              $queue = 'A';
            } else if ($i%3 == 2) {
              $queue = 'B';
            }
            //sleep(random_int(0, 2));
            QueueJobs::dispatch('优先级队列=>当前优先队列为：' . $queue . '，入队时间：' . date("Y-m-d H:i:s"))->onQueue($queue);
            $this->info('优先级队列=>任务已发送到队列！');
        }
    }
    
}
